import joblib

from csst.core.processor import CsstProcessor
from csst.msc.data_manager import CsstMscDataManager


class CsstProcPhotonAbsorption(CsstProcessor):
    """ This processor absorbs photons """

    def __init__(self, dm: CsstMscDataManager, n_jobs: int = 1):
        super(CsstProcPhotonAbsorption, self).__init__()
        self.dm = dm
        self.n_jobs = n_jobs

    def run(self, debug=False):
        """ run this processor

        Parameters
        ----------
        debug
            if True, use debug mode

        Returns
        -------

        """
        joblib.Parallel(n_jobs=self.n_jobs)(
            joblib.delayed(CsstProcPhotonAbsorption.run_one_chip)(this_ccd_id)
            for this_ccd_id in self.dm.target_ccd_ids)
        return

    def prepare(self, **kwargs):
        """ prepare the environment """
        return

    def cleanup(self):
        """ clean up the environment """
        return

    @staticmethod
    def run_one_chip(ccd_id):
        """ run for one chip """
        return
